const api = require('./api')



const go_search_jg=(e)=>{
    wx.navigateTo({
      url: '/pages/jgs/search_jg/search_jg',
    })
  }


  // 查看机构
const tap_jg=(that,e)=>{
    let index = e.currentTarget.id
    that.setData({
      sel_index:index,
    })
    let jg_id = that.data.jg_list[index].jg_id
    let short_name = that.data.jg_list[index].short_name
    wx.showActionSheet({
      itemList: ['机构主页','学生情况','变更负责人','设置机构失效日期','设置机构状态'],
      success: res => {
        if(res.tapIndex==0){
          wx.navigateTo({
            url:'/pages/jgs/jg_homePage/jg_homePage?jg_id=' + jg_id
          })
        }else if(res.tapIndex==1){
          wx.navigateTo({
            url: '/pages/students/index/index?jg_id=' + jg_id + '&jg_name=' + short_name,
            fail:err=>{
              console.log('err',err)
            }
          })
        }else if(res.tapIndex==2){
          wx.navigateTo({
            url: '/pages/jgs/jg_header/jg_header?jg_id=' + jg_id,
          })
        }else if(res.tapIndex==3){
          wx.navigateTo({
            url:'/pages/jgs/jg_permission/jg_permission?jg_id=' + jg_id
          })
        }else if(res.tapIndex==4){
          set_jg_status(that,jg_id)
        }
      },
    })

  }
  // 开通机构
const create_jg=()=>{
    wx.navigateTo({
      url: '/pages/jgs/create_jg/create_jg',
    })
  }


  // 更新机构状态
const set_jg_status=(that,jg_id)=>{
    wx.showActionSheet({
      itemList: ['设置为“未提交”','设置为“待审核”','设置为“已认证”','设置为“已失效”','设置为“待认领”'],
      success: res => {
        if(res.tapIndex==0){
          var set_status = '0'  // 0-未提交
        }else if(res.tapIndex==1){
          var set_status = '1'  // // 1-待审核
        }else if(res.tapIndex==2){
          var set_status = '2'  // 2-已认证
        }else if(res.tapIndex==3){
          var set_status = '3'  // 3-已失效
        }else if(res.tapIndex==4){
          var set_status = '4'  // 4-待认领
        }
        api.update_jg_status(that,jg_id,set_status)  // 0-未提交
      },
    })
  }



  // 选择标签
const sel_label=(that,e)=>{
    let index = e.detail.index
    let docks = that.data.docks
    that.jg_status = docks[index].name
    that.setData({
      no_more:false,
    })
    that.page_no = 0
    api.load_jg_list(that,that.jg_status,0)
  }


  module.exports={
    sel_label:sel_label,
    create_jg:create_jg,
    tap_jg:tap_jg,
    go_search_jg:go_search_jg,
    set_jg_status:set_jg_status,
  }